package com.qnbc.mystery.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qnbc.mystery.core.annotation.Log;
import com.qnbc.mystery.core.controller.BaseController;
import com.qnbc.mystery.core.domain.AjaxResult;
import com.qnbc.mystery.core.enums.BusinessType;
import com.qnbc.mystery.core.utils.poi.ExcelUtil;
import com.qnbc.mystery.pojo.domain.User;
import com.qnbc.mystery.utils.TokenUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.qnbc.mystery.domain.WinRecord;
import com.qnbc.mystery.service.IWinRecordService;

/**
 * 开奖记录
 *
 * @author guzj
 * @date 2024-03-04
 */
@RestController
@RequestMapping("/mystery/record")
public class WinRecordController extends BaseController {
    @Autowired
    private IWinRecordService winRecordService;

    /**
     * 查询开奖记录列表
     */
    @GetMapping("/list")
    public AjaxResult list( WinRecord winRecord) {
        User currentUser = TokenUtils.getCurrentUser();
        winRecord.setCreatedBy(String.valueOf(currentUser.getId()));
        PageHelper.startPage(winRecord.getPageNum(), winRecord.getPageSize());
        List<WinRecord> list = winRecordService.selectWinRecordList(winRecord);
        PageInfo<WinRecord> pageInfo = new PageInfo(list);
        return AjaxResult.success(pageInfo);
    }

    /**
     * 导出开奖记录列表
     */
    @Log(title = "开奖记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WinRecord winRecord) {
        List<WinRecord> list = winRecordService.selectWinRecordList(winRecord);
        ExcelUtil<WinRecord> util = new ExcelUtil<WinRecord>(WinRecord.class);
        util.exportExcel(response, list, "开奖记录数据");
    }

    /**
     * 获取开奖记录详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(winRecordService.selectWinRecordById(id));
    }

    /**
     * 新增开奖记录
     */
    @Log(title = "开奖记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WinRecord winRecord) {
        return toAjax(winRecordService.insertWinRecord(winRecord));
    }

    /**
     * 修改开奖记录
     */
    @Log(title = "开奖记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WinRecord winRecord) {
        return toAjax(winRecordService.updateWinRecord(winRecord));
    }

    /**
     * 删除开奖记录
     */
    @Log(title = "开奖记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(winRecordService.deleteWinRecordByIds(ids));
    }
}
